<template>
  <div class="system-tenant-container">
    <!-- 文档提示 -->
    <div class="doc-alert-wrapper">
      <doc-alert
        title="SaaS 多租户"
        url="https://doc.iocoder.cn/saas-tenant/"
        class="enhanced-doc-alert"
      />
    </div>

    <!-- 搜索区域 -->
    <ContentWrap class="search-wrapper">
      <!-- 搜索头部 -->
      <div class="search-header">
        <div class="header-icon">
          <Icon icon="ep:office-building" />
        </div>
        <div class="header-content">
          <h3 class="search-title">租户管理</h3>
          <p class="search-subtitle">管理系统中的多租户信息</p>
        </div>
      </div>

      <!-- 搜索表单 -->
      <div class="search-form-container">
        <el-form
          :model="queryParams"
          ref="queryFormRef"
          :inline="true"
          label-width="100px"
          label-position="left"
          class="enhanced-search-form"
        >
          <div class="form-grid">
            <el-form-item label="租户名" prop="name" class="form-item">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入租户名"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:office-building" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="租户类型" prop="bizType" class="form-item">
              <el-select
                v-model="queryParams.bizType"
                class="enhanced-select"
                placeholder="请选择租户类型"
              >
                <template #prefix>
                  <Icon icon="ep:collection-tag" />
                </template>
                <el-option label="普通租户" value="1"></el-option>
                <el-option label="代理商" value="2"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="联系人" prop="contactName" class="form-item">
              <el-input
                v-model="queryParams.contactName"
                placeholder="请输入联系人"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:user" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="联系手机" prop="contactMobile" class="form-item">
              <el-input
                v-model="queryParams.contactMobile"
                placeholder="请输入联系手机"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:phone" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="租户状态" prop="status" class="form-item">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择租户状态"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:switch" />
                </template>
                <el-option
                  v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>

            <el-form-item label="创建时间" prop="createTime" class="form-item">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
                class="enhanced-date-picker"
              />
            </el-form-item>
          </div>

          <div class="form-actions">
            <el-button @click="handleQuery" class="search-btn">
              <Icon icon="ep:search" class="btn-icon" />
              搜索
            </el-button>
            <el-button @click="resetQuery" class="reset-btn">
              <Icon icon="ep:refresh" class="btn-icon" />
              重置
            </el-button>
            <el-button
              type="primary"
              plain
              @click="openForm('create')"
              v-hasPermi="['system:tenant:create']"
              class="create-btn"
            >
              <Icon icon="ep:plus" class="btn-icon" />
              新增
            </el-button>
            <el-button
              type="success"
              plain
              @click="handleExport"
              :loading="exportLoading"
              v-hasPermi="['system:tenant:export']"
              class="export-btn"
            >
              <Icon icon="ep:download" class="btn-icon" />
              导出
            </el-button>
          </div>
        </el-form>
      </div>
    </ContentWrap>

    <!-- 列表 -->
    <ContentWrap class="table-wrapper">
      <!-- 表格头部 -->
      <div class="table-header">
        <div class="header-icon">
          <Icon icon="ep:list" />
        </div>
        <div class="header-content">
          <h4 class="table-title">租户列表</h4>
          <p class="table-subtitle">共 {{ total }} 个租户</p>
        </div>
      </div>

      <!-- 表格容器 -->
      <div class="table-container">
        <el-table
          v-loading="loading"
          :data="list"
          border
          class="enhanced-table"
          :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
        >
          <el-table-column label="租户编号" prop="id" width="120px">
            <template #default="scope">
              <div class="id-cell">
                <Icon icon="ep:key" class="id-icon" />
                <span class="id-text">{{ scope.row.id }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="租户名" align="left" prop="name" width="200px">
            <template #default="scope">
              <div class="name-cell">
                <el-tag
                  class="tenant-type-tag"
                  :type="scope.row.bizType == 2 ? 'danger' : 'primary'"
                  effect="dark"
                >
                  <Icon
                    :icon="scope.row.bizType == 1 ? 'ep:office-building' : 'ep:user'"
                    class="tag-icon"
                  />
                  {{ scope.row.bizType == 1 ? '租户' : '代理' }}
                </el-tag>
                <span class="tenant-name">{{ scope.row.name }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="联系人" prop="contactName" width="140px">
            <template #default="scope">
              <div class="contact-cell">
                <Icon icon="ep:user" class="contact-icon" />
                <span class="contact-text">{{ scope.row.contactName || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="联系手机" prop="contactMobile" width="160px">
            <template #default="scope">
              <div class="mobile-cell">
                <Icon icon="ep:phone" class="mobile-icon" />
                <span class="mobile-text">{{ scope.row.contactMobile || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="余额" prop="wallet" width="100px">
            <template #default="scope">
              <div class="wallet-cell">
                <Icon icon="ep:wallet" class="wallet-icon" />
                <span class="wallet-amount">{{ scope.row.wallet || '0' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="套餐余额" width="150px">
            <template #default="scope">
              <div class="package-cell">
                <div class="package-list" v-if="scope.row.tenantProduct">
                  <div
                    v-for="item in scope.row.tenantProduct"
                    :key="item.tenantId"
                    class="package-item"
                  >
                    <span class="package-name">{{ item.productName }}</span>
                    <span class="package-remain">{{ item.remainNum }}</span>
                  </div>
                </div>
                <span v-else class="no-package">暂无套餐</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="话费成本价" prop="callCostPrice" width="120px">
            <template #default="scope">
              <div class="price-cell">
                <Icon icon="ep:money" class="price-icon" />
                <span class="price-text">{{ scope.row.callCostPrice || '0' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="话费销售价" prop="callSalePrice" width="120px">
            <template #default="scope">
              <div class="price-cell">
                <Icon icon="ep:sell" class="price-icon" />
                <span class="price-text">{{ scope.row.callSalePrice || '0' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="绑定域名" align="center" prop="website" width="200">
            <template #default="scope">
              <div class="website-cell">
                <Icon icon="ep:link" class="website-icon" />
                <span class="website-text">{{ scope.row.website || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="租户状态" align="center" prop="status" width="120">
            <template #default="scope">
              <div class="status-cell">
                <dict-tag
                  :type="DICT_TYPE.COMMON_STATUS"
                  :value="scope.row.status"
                  class="enhanced-dict-tag"
                />
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            width="200"
            :formatter="dateFormatter"
          >
            <template #default="scope">
              <div class="time-cell">
                <Icon icon="ep:clock" class="time-icon" />
                <span>{{ dateFormatter(scope.row, null, scope.row.createTime) }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="过期时间"
            align="center"
            prop="expireTime"
            width="200"
            :formatter="dateFormatter"
          >
            <template #default="scope">
              <div class="expire-time-cell">
                <Icon icon="ep:warning" class="expire-icon" />
                <span>{{ dateFormatter(scope.row, null, scope.row.expireTime) || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="360" fixed="right">
            <template #default="scope">
              <div class="action-buttons">
                <el-button
                  link
                  type="primary"
                  v-hasPermi="['system:tenant:update']"
                  @click="configureTenants(scope.row, scope.row.id)"
                  class="action-btn config-btn"
                  size="small"
                >
                  <Icon icon="ep:setting" class="btn-icon" />
                  配置租户
                </el-button>
                <el-button
                  link
                  type="primary"
                  @click="openForm('update', scope.row.id)"
                  v-hasPermi="['system:tenant:update']"
                  class="action-btn edit-btn !ml-0"
                  size="small"
                >
                  <Icon icon="ep:edit" class="btn-icon" />
                  编辑
                </el-button>
                <el-button
                  link
                  type="primary"
                  :disabled="scope.row.bizType == 2"
                  @click="wentURL(scope.row)"
                  class="action-btn jump-btn !ml-0"
                  size="small"
                >
                  <Icon icon="ep:position" class="btn-icon" />
                  跳转
                </el-button>
                <el-button
                  link
                  type="danger"
                  @click="handleDelete(scope.row.id)"
                  v-hasPermi="['system:tenant:delete']"
                  class="action-btn delete-btn !ml-0"
                  size="small"
                >
                  <Icon icon="ep:delete" class="btn-icon" />
                  删除
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </ContentWrap>

    <!-- 表单弹窗：添加/修改 -->
    <TenantForm ref="formRef" @success="getList" />
  </div>
</template>

<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as TenantApi from '@/api/system/tenant'
import * as TenantPackageApi from '@/api/system/tenantPackage'
import TenantForm from './TenantForm.vue'
import AccountForm from './AccountForm.vue'
import * as authUtil from '@/utils/auth'
import { useUserStore } from '@/store/modules/user'
import { useTagsViewStore } from '@/store/modules/tagsView'
import log from '@/utils/log.ts'

defineOptions({ name: 'SystemTenant' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: undefined,
  contactName: undefined,
  contactMobile: undefined,
  status: undefined,
  createTime: [],
  bizType: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
const packageList = ref([] as TenantPackageApi.TenantPackageVO[]) //租户套餐列表

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await TenantApi.getTenantPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}
const router = useRouter()
const userStore = useUserStore()
const tagsViewStore = useTagsViewStore()
/** 配置租户 */
const configureTenants = (item, id) => {
  router.push('/system/configure-tenants?id=' + id)
}
/**
 *钱包充值
 */
const walletRecharge = () => {
  log.success('钱包充值', 123)
}
/*跳转*/
const wentURL = async (row) => {
  const data = await TenantApi.jumpLogin(row.id)
  if (data) {
    await userStore.loginOut()
    await authUtil.setTenantId(data.tenantId)
    await authUtil.setTenantSign(row.sign)
    await authUtil.setToken(data)
    tagsViewStore.setRefreshTag(true)
    router.replace('/login?redirect=/index')
  }
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await TenantApi.deleteTenant(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await TenantApi.exportTenant(queryParams)
    download.excel(data, '租户列表.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(async () => {
  await getList()
  packageList.value = await TenantPackageApi.getTenantPackageList()
})
</script>

<style lang="scss" scoped>
// 主题色变量
$primary-color: #0052cc;
$primary-light: rgba(0, 82, 204, 0.1);
$primary-border: rgba(0, 82, 204, 0.3);
$success-color: #67c23a;
$warning-color: #e6a23c;
$danger-color: #f56c6c;
$info-color: #909399;
$text-primary: #303133;
$text-regular: #606266;
$text-secondary: #909399;
$text-placeholder: #c0c4cc;
$border-color: #dcdfe6;
$border-light: #e4e7ed;
$bg-color: #f5f7fa;
$shadow-light: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
$shadow-base:
  0 2px 4px rgba(0, 0, 0, 0.12),
  0 0 6px rgba(0, 0, 0, 0.04);
$border-radius: 12px;
$border-radius-small: 8px;

.system-tenant-container {
  padding: 16px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;

  @media (max-width: 768px) {
    padding: 8px;
  }
}

/* 文档提示样式 */
.doc-alert-wrapper {
  margin-bottom: 16px;

  .enhanced-doc-alert {
    border-radius: $border-radius;
    box-shadow: $shadow-light;
    border: 1px solid $border-light;
    overflow: hidden;

    :deep(.el-alert) {
      border-radius: $border-radius;
    }

    :deep(.el-alert__icon) {
      color: $primary-color;
    }

    :deep(.el-alert__title) {
      color: $text-primary;
      font-weight: 600;
    }
  }
}

/* 搜索区域样式 */
.search-wrapper {
  margin-bottom: 16px;
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.search-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;
  border-bottom: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: $border-radius-small;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;

  @media (max-width: 768px) {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

.header-content {
  flex: 1;
  margin-left: 16px;

  @media (max-width: 768px) {
    margin-left: 0;
  }
}

.search-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 18px;
  }
}

.search-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.search-form-container {
  background: white;
  padding: 24px;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-search-form {
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;

    @media (max-width: 768px) {
      grid-template-columns: 1fr;
      gap: 16px;
    }
  }

  .form-item {
    margin-bottom: 0;

    :deep(.el-form-item__label) {
      font-weight: 500;
      color: $text-regular;
    }
  }
}

.enhanced-input,
.enhanced-select,
.enhanced-date-picker {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }
}

.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;

  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.search-btn {
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  border: none;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  color: white;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.reset-btn {
  border: 2px solid $border-color;
  color: $text-regular;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    border-color: $primary-color;
    color: $primary-color;
    background: $primary-light;
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.create-btn {
  border: 2px solid $primary-color;
  color: $primary-color;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    background: $primary-color;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.export-btn {
  border: 2px solid $success-color;
  color: $success-color;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    background: $success-color;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(103, 194, 58, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 表格区域样式 */
.table-wrapper {
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.table-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%);
  border-bottom: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
  }

  .header-icon {
    width: 40px;
    height: 40px;
    background: $primary-color;
    border-radius: $border-radius-small;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0;

    @media (max-width: 768px) {
      width: 36px;
      height: 36px;
      font-size: 16px;
    }
  }

  .header-content {
    flex: 1;
    margin-left: 12px;

    @media (max-width: 768px) {
      margin-left: 10px;
    }
  }

  .table-title {
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 2px 0;

    @media (max-width: 768px) {
      font-size: 14px;
    }
  }

  .table-subtitle {
    font-size: 13px;
    color: $text-secondary;
    margin: 0;

    @media (max-width: 768px) {
      font-size: 12px;
    }
  }
}

.table-container {
  background: white;
  overflow-x: auto;
}

.enhanced-table {
  :deep(.el-table__header) {
    th {
      background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%) !important;
      color: $text-primary !important;
      font-weight: 600 !important;
      border-bottom: 2px solid $primary-light;
      padding: 16px 12px;
    }
  }

  :deep(.el-table__body) {
    tr {
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light !important;
      }

      td {
        padding: 14px 12px;
        border-bottom: 1px solid $border-light;
      }
    }

    .el-table__row--striped {
      background: #fafbff;

      &:hover {
        background: $primary-light !important;
      }
    }
  }

  // H5适配
  @media (max-width: 768px) {
    :deep(.el-table__header) th {
      padding: 12px 8px;
      font-size: 13px;
    }

    :deep(.el-table__body) td {
      padding: 12px 8px;
      font-size: 12px;
    }
  }
}

/* 表格单元格样式 */
.id-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.id-icon {
  color: $primary-color;
  font-size: 14px;
  flex-shrink: 0;
}

.id-text {
  font-weight: 500;
  color: $text-primary;
  font-family: 'Courier New', monospace;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tenant-type-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-weight: 500;
  padding: 4px 8px;
  font-size: 11px;
  flex-shrink: 0;

  .tag-icon {
    font-size: 12px;
  }

  @media (max-width: 768px) {
    font-size: 10px;
    padding: 3px 6px;
  }
}

.tenant-name {
  font-weight: 600;
  color: $text-primary;
  flex: 1;
}

.contact-cell,
.mobile-cell,
.wallet-cell,
.price-cell,
.website-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.contact-icon {
  color: $info-color;
  font-size: 14px;
}

.mobile-icon {
  color: $success-color;
  font-size: 14px;
}

.wallet-icon {
  color: $warning-color;
  font-size: 14px;
}

.price-icon {
  color: $danger-color;
  font-size: 14px;
}

.website-icon {
  color: $primary-color;
  font-size: 14px;
}

.contact-text,
.mobile-text,
.price-text,
.website-text {
  color: $text-regular;
  font-size: 13px;
}

.wallet-amount {
  color: $warning-color;
  font-weight: 600;
  font-size: 13px;
}

.package-cell {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.package-icon {
  color: $info-color;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.package-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}

.package-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
}

.package-name {
  color: $text-regular;
  flex: 1;
}

.package-remain {
  color: $primary-color;
  font-weight: 600;
}

.no-package {
  color: $text-placeholder;
  font-style: italic;
  font-size: 12px;
}

.status-cell {
  display: flex;
  justify-content: center;
  align-items: center;
}

.time-cell,
.expire-time-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: 12px;
  color: $text-secondary;
}

.time-icon {
  color: $text-secondary;
  font-size: 14px;
}

.expire-icon {
  color: $warning-color;
  font-size: 14px;
}

.enhanced-dict-tag {
  border-radius: 6px;
  font-weight: 500;
  padding: 4px 8px;
  font-size: 12px;

  @media (max-width: 768px) {
    font-size: 11px;
    padding: 3px 6px;
  }
}

/* 操作按钮样式 */
.action-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 4px;
  }
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;

  &:hover {
    transform: scale(1.05);
  }

  .btn-icon {
    font-size: 12px;
  }

  @media (max-width: 768px) {
    padding: 4px 8px;
    font-size: 11px;
    justify-content: center;
  }

  &.config-btn:hover {
    background: rgba(144, 147, 153, 0.1);
    color: $info-color;
  }

  &.edit-btn:hover {
    background: $primary-light;
    color: $primary-color;
  }

  &.jump-btn:hover {
    background: rgba(103, 194, 58, 0.1);
    color: $success-color;
  }

  &.delete-btn:hover {
    background: rgba(245, 108, 108, 0.1);
    color: $danger-color;
  }
}

/* 分页样式 */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px 24px;
  background: white;
  border-top: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
  }

  :deep(.el-pagination) {
    .el-pager li {
      border-radius: 6px;
      margin: 0 2px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }

      &.is-active {
        background: $primary-color;
        color: white;
      }
    }

    .btn-prev,
    .btn-next {
      border-radius: 6px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }
    }

    @media (max-width: 768px) {
      .el-pagination__sizes,
      .el-pagination__jump {
        display: none;
      }
    }
  }
}

/* 响应式优化 */
@media (max-width: 480px) {
  .system-tenant-container {
    padding: 4px;
  }

  .search-form-container {
    padding: 12px;
  }

  .form-actions {
    gap: 8px;

    .el-button {
      padding: 8px 12px;
      font-size: 13px;
    }
  }

  .enhanced-table {
    :deep(.el-table__header) th {
      padding: 10px 6px;
      font-size: 12px;
    }

    :deep(.el-table__body) td {
      padding: 10px 6px;
      font-size: 11px;
    }
  }

  .pagination-wrapper {
    padding: 12px;
  }

  .package-list {
    font-size: 11px;
  }

  .tenant-name {
    font-size: 12px;
  }
}

/* 加载状态优化 */
:deep(.el-loading-mask) {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(2px);

  .el-loading-spinner {
    .path {
      stroke: $primary-color;
    }
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .system-tenant-container {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  }

  .search-wrapper,
  .table-wrapper {
    background: #374151;
    border-color: #4b5563;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .search-form-container,
  .table-container,
  .pagination-wrapper {
    background: #374151;
  }

  .table-header {
    background: #4b5563;
    border-color: #6b7280;
  }

  .search-title,
  .table-title {
    color: #f9fafb;
  }

  .tenant-name,
  .id-text {
    color: #f9fafb;
  }

  .contact-text,
  .mobile-text,
  .price-text,
  .website-text,
  .package-name {
    color: #d1d5db;
  }

  .enhanced-table {
    :deep(.el-table__header) {
      th {
        background: #4b5563 !important;
        color: #f9fafb !important;
        border-bottom-color: #6b7280;
      }
    }

    :deep(.el-table__cell) {
      border-bottom-color: #4b5563;
    }
  }

  .tenant-type-tag {
    &.el-tag--primary {
      background: rgba(96, 165, 250, 0.1);
      color: #60a5fa;
      border-color: rgba(96, 165, 250, 0.3);
    }

    &.el-tag--danger {
      background: rgba(248, 113, 113, 0.1);
      color: #f87171;
      border-color: rgba(248, 113, 113, 0.3);
    }
  }

  .enhanced-doc-alert {
    :deep(.el-alert) {
      background: #374151;
      border-color: #4b5563;
    }

    :deep(.el-alert__title) {
      color: #f9fafb;
    }

    :deep(.el-alert__icon) {
      color: #60a5fa;
    }
  }
}
</style>
